package com.myzl.stream.service.impl;

import com.myzl.common.config.VideoConfig;
import com.myzl.common.utils.StreamUtil;
import com.myzl.stream.pojo.ImageData;
import com.myzl.stream.service.IVideoConversionService;
import com.myzl.stream.config.ConversionVideo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author cew
 * @date 2023年7月20日10:23:30
 */
@Slf4j(topic = "admin-steam")
@Service
public class IVideoConversionServiceImpl implements IVideoConversionService {

    @Autowired
    private ConversionVideo conversionVideo;

    @Override
    public String live(ImageData imageData) {
        String rtspUrl = StreamUtil.getRtspUrl(imageData.getUsername(), imageData.getPassword(),imageData.getChannel(), imageData.getIp(), imageData.getPort());
        String rtmpUrl = StreamUtil.getRtmpUrl(VideoConfig.getFlvIp(), VideoConfig.getFlvPort(),imageData.getDeviceId());
        String flvUrl = StreamUtil.flvUrl(VideoConfig.getFlvPort(), imageData.getDeviceId());
        return conversionVideo.pushVideoAsRTSP(rtspUrl, rtmpUrl, flvUrl);
    }

    @Override
    public boolean keepLive(ImageData imageData) {
        String rtspUrl = StreamUtil.getRtspUrl(imageData.getUsername(), imageData.getPassword(),imageData.getChannel(), imageData.getIp(), imageData.getPort());
        return conversionVideo.keepLive(rtspUrl);
    }

    @Override
    public boolean destroy(ImageData imageData) {
        String rtspUrl = StreamUtil.getRtspUrl(imageData.getUsername(), imageData.getPassword(),imageData.getChannel(), imageData.getIp(), imageData.getPort());
        return conversionVideo.destroy(rtspUrl);
    }
}
